using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public abstract class SkillDeployer : MonoBehaviour
{
    private SkillData _data;
    public SkillData Data
    {
        get => _data;
        set
        {
            _data = value;
            InitDeployer();
        }
    }

    private ISkillSelector _selector;
    private ISkillImpact[] _impacts;

    /// <summary>
    /// 选择目标
    /// </summary>
    public void CalculateTargets()
    {
        Data.attackTargets = _selector.SelectTarget(Data, transform);
    }

    /// <summary>
    /// 执行所有印象
    /// </summary>
    public void ImpactTargets()
    {
        foreach (var impact in _impacts)
        {
            impact.Execute(this);
        }
    }

    /// <summary>
    /// 部署技能
    /// </summary>
    public abstract void DeploySkill();

    /// <summary>
    /// 初始化部署器
    /// </summary>
    private void InitDeployer()
    {
        _selector = CreateSkillSelector(Data.item.selectorType);
        _impacts = new ISkillImpact[Data.item.impactTypes.Length];
        for (int i = 0; i < Data.item.impactTypes.Length; i++)
        {
            _impacts[i] = CreateSkillImpact(Data.item.impactTypes[i]);
        }
    }

    /// <summary>
    /// 创建技能选择器
    /// </summary>
    private ISkillSelector CreateSkillSelector(SkillSelectorType selctorType)
    {
        switch (selctorType)
        {
            case SkillSelectorType.Sector:
                return new SectorSkillSelector();
            case SkillSelectorType.Rectangle:
                return new RectangleSkillSelector();
            default:
                return null;
        }
    }

    /// <summary>
    /// 创建技能影响类
    /// </summary>
    private ISkillImpact CreateSkillImpact(SkillImpactType impactType)
    {
        switch (impactType)
        {
            case SkillImpactType.CostSP:
                return new CostSPImpact();
            case SkillImpactType.Damage:
                return new DamageImpact();
            default:
                return null;
        }
    }
}
